<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="../../../../lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.useso.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="../../../../lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="../../../../css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="../../../../images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="../../../../images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="../../../../images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="../../../../images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Floating,keepalived,lvs,">










<meta name="description" content="说明： 本文档仅围绕lvs+keepalived如何实现负载均衡、故障剔除、后端realserver健康监测、主备切换邮件通知;而防火墙、网络(路由交换)、后端数据存储、内外网暂未考虑; 一、环境准备： 1.操作系统 CentOS6.4-x86_64 2.软件版本： ipvsadm-1.25-10.el6.x86_64keepalived-1.2.7-3.el6.x86_64httpd-2.2.1">
<meta name="keywords" content="Floating,keepalived,lvs">
<meta property="og:type" content="article">
<meta property="og:title" content="LVS+Keepalived">
<meta property="og:url" content="http://demo_demo.gitee.io/2014/10/31/lvskeepalived/index.html">
<meta property="og:site_name" content="运维人">
<meta property="og:description" content="说明： 本文档仅围绕lvs+keepalived如何实现负载均衡、故障剔除、后端realserver健康监测、主备切换邮件通知;而防火墙、网络(路由交换)、后端数据存储、内外网暂未考虑; 一、环境准备： 1.操作系统 CentOS6.4-x86_64 2.软件版本： ipvsadm-1.25-10.el6.x86_64keepalived-1.2.7-3.el6.x86_64httpd-2.2.1">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/1.png">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/13.png">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/14.png">
<meta property="og:updated_time" content="2018-12-10T10:49:03.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="LVS+Keepalived">
<meta name="twitter:description" content="说明： 本文档仅围绕lvs+keepalived如何实现负载均衡、故障剔除、后端realserver健康监测、主备切换邮件通知;而防火墙、网络(路由交换)、后端数据存储、内外网暂未考虑; 一、环境准备： 1.操作系统 CentOS6.4-x86_64 2.软件版本： ipvsadm-1.25-10.el6.x86_64keepalived-1.2.7-3.el6.x86_64httpd-2.2.1">
<meta name="twitter:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://demo_demo.gitee.io/2014/10/31/lvskeepalived/">





  <title>LVS+Keepalived | 运维人</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/guomaoqiu" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#FD6C6C; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">运维人</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">生命在于折腾</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://demo_demo.gitee.io">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OutMan">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维人">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">LVS+Keepalived</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2014-10-31T10:54:30+08:00">
                2014-10-31
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="../../../../categories/负载均衡/" itemprop="url" rel="index">
                    <span itemprop="name">负载均衡</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>说明： 本文档仅围绕lvs+keepalived如何实现负载均衡、故障剔除、后端realserver健康监测、主备切换邮件通知;而防火墙、网络(路由交换)、后端数据存储、内外网暂未考虑; <strong>一、环境准备：</strong> 1.操作系统</p>
<p>CentOS6.4-x86_64</p>
<p>2.软件版本：</p>
<p>ipvsadm-1.25-10.el6.x86_64<br>keepalived-1.2.7-3.el6.x86_64<br>httpd-2.2.15-26.el6.centos.x86_64</p>
<p>3.实验拓扑： <a href="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/1.png" target="_blank" rel="noopener"><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/1.png" alt="1"></a> 4.时间同步：<br><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">node1</span>:</span><br><span class="line">\[root<span class="variable">@node1</span> ~\]# ntpdate <span class="number">203.117</span>.<span class="number">180.36</span></span><br><span class="line">\[root<span class="variable">@node1</span> ~\]# echo <span class="string">"*/10 * * * * /usr/sbin/ntpdate 203.117.180.36"</span> &gt;&gt; /etc/crontab</span><br><span class="line"><span class="attribute">node2</span>:</span><br><span class="line">\[root<span class="variable">@node2</span> ~\]# ntpdate <span class="number">203.117</span>.<span class="number">180.36</span></span><br><span class="line">\[root<span class="variable">@node1</span> ~\]# echo <span class="string">"*/10 * * * * /usr/sbin/ntpdate 203.117.180.36"</span> &gt;&gt; /etc/crontab</span><br><span class="line"><span class="attribute">master</span>:</span><br><span class="line">\[root<span class="variable">@master</span> ~\]# ntpdate <span class="number">203.117</span>.<span class="number">180.36</span></span><br><span class="line">\[root<span class="variable">@master</span> ~\]# echo <span class="string">"*/10 * * * * /usr/sbin/ntpdate 203.117.180.36"</span> &gt;&gt; /etc/crontab</span><br><span class="line"><span class="attribute">Slave</span>:</span><br><span class="line">\[root<span class="variable">@slave</span> ~\]# ntpdate <span class="number">203.117</span>.<span class="number">180.36</span></span><br><span class="line">\[root<span class="variable">@slave</span> ~\]# echo <span class="string">"*/10 * * * * /usr/sbin/ntpdate 203.117.180.36"</span> &gt;&gt; /etc/crontab</span><br></pre></td></tr></table></figure></p>
<p>5.主机名相互解析：</p>
<figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">node1</span>:</span><br><span class="line">\[root<span class="variable">@node1</span> ~\]# cat /etc/hosts</span><br><span class="line"><span class="number">127.0</span>.<span class="number">0.1</span>   localhost localhost.localdomain localhost4 localhost4.localdomain4 </span><br><span class="line">::<span class="number">1</span>         localhost localhost.localdomain localhost6 localhost6.localdomain6 </span><br><span class="line"><span class="number">192.168</span>.<span class="number">254.201</span>    node1.test.com    node1 </span><br><span class="line"><span class="number">192.168</span>.<span class="number">254.202</span>    node2.test.com    node2</span><br><span class="line"><span class="attribute">node2</span>:</span><br><span class="line">\[root<span class="variable">@node2</span> ~\]# cat /etc/hosts</span><br><span class="line"><span class="number">127.0</span>.<span class="number">0.1</span>   localhost localhost.localdomain localhost4 localhost4.localdomain4 </span><br><span class="line">::<span class="number">1</span>         localhost localhost.localdomain localhost6 localhost6.localdomain6 </span><br><span class="line"><span class="number">192.168</span>.<span class="number">254.201</span>    node1.test.com    node1 </span><br><span class="line"><span class="number">192.168</span>.<span class="number">254.202</span>    node2.test.com    node2</span><br></pre></td></tr></table></figure>
<p>6.安装yum源：(其他三台主机上面同样执行以下两条命令即可，前提:能上网)<br><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">node1</span>:</span><br><span class="line">\[root<span class="variable">@node1</span>~\]#</span><br><span class="line">rpm -ivh <span class="attribute">http</span>:<span class="comment">//download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm</span></span><br><span class="line">\[root<span class="variable">@node1</span> ~\]# rpm -ivh <span class="attribute">http</span>:<span class="comment">//elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm</span></span><br></pre></td></tr></table></figure></p>
<p><strong>二、**</strong>web<strong>**节点安装配置：</strong> 安装web服务并执行realserver.sh,为lo:0绑定VIP地址192.168.254.200，抑制ARP广播; node1/node2配置：<br><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">\[root@node1 ~\]# yum install -y httpd        </span><br><span class="line">\[root@node1 ~\]# echo <span class="string">"&lt;h1&gt;Rs1.test.com&lt;/h1&gt;"</span> &gt; /var/www/html/index.html</span><br><span class="line">\[root@node1 ~\]#<span class="built_in"> service </span>httpd start</span><br><span class="line">\[root@node1 ~\]# chkconfig httpd on</span><br><span class="line">\[root@node1 ~\]# mkdir script</span><br><span class="line">\[root@node1 ~\]# cd script/</span><br><span class="line">\[root@node1 ~\]# vim script/realserver.sh</span><br><span class="line"><span class="comment">#-&gt;LVS客户端配置脚本realserver.sh：</span></span><br><span class="line"><span class="comment">#!/bin/bash </span></span><br><span class="line">\#<span class="built_in"> Script </span><span class="keyword">to</span> start LVS DR real server.  </span><br><span class="line">\# description: LVS DR real<span class="built_in"> server </span> </span><br><span class="line"></span><br><span class="line">.  /etc/rc.d/init.d/functions</span><br><span class="line"><span class="attribute">VIP</span>=192.168.254.200 </span><br><span class="line"><span class="attribute">host</span>=`/bin/hostname`</span><br><span class="line">case <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span> </span><br><span class="line">start)  </span><br><span class="line">       # Start LVS-DR real<span class="built_in"> server </span>on this machine.  </span><br><span class="line">       /sbin/ifconfig lo down  </span><br><span class="line">        /sbin/ifconfig lo up  </span><br><span class="line">        echo 1 &gt; /proc/sys/net/ipv4/conf/lo/arp_ignore  </span><br><span class="line">        echo 2 &gt; /proc/sys/net/ipv4/conf/lo/arp_announce  </span><br><span class="line">        echo 1 &gt; /proc/sys/net/ipv4/conf/all/arp_ignore  </span><br><span class="line">        echo 2 &gt; /proc/sys/net/ipv4/conf/all/arp_announce</span><br><span class="line">        /sbin/ifconfig lo:0 <span class="variable">$VIP</span> broadcast <span class="variable">$VIP</span> netmask 255.255.255.255 up </span><br><span class="line">        /sbin<span class="built_in">/route </span><span class="builtin-name">add</span> -host <span class="variable">$VIP</span> dev lo:0</span><br><span class="line">;; </span><br><span class="line"></span><br><span class="line">stop)</span><br><span class="line"></span><br><span class="line">        # Stop LVS-DR real<span class="built_in"> server </span>loopback device(s). </span><br><span class="line">        /sbin/ifconfig lo:0 down  </span><br><span class="line">        echo 0 &gt; /proc/sys/net/ipv4/conf/lo/arp_ignore  </span><br><span class="line">        echo 0 &gt; /proc/sys/net/ipv4/conf/lo/arp_announce  </span><br><span class="line">        echo 0 &gt; /proc/sys/net/ipv4/conf/all/arp_ignore  </span><br><span class="line">        echo 0 &gt; /proc/sys/net/ipv4/conf/all/arp_announce</span><br><span class="line">;; </span><br><span class="line"></span><br><span class="line">status)</span><br><span class="line">        # Status of LVS-DR real server. </span><br><span class="line">        <span class="attribute">islothere</span>=`/sbin/ifconfig lo:0 | grep <span class="variable">$VIP</span>`  </span><br><span class="line">        <span class="attribute">isrothere</span>=\`netstat -rn | grep <span class="string">"lo:0"</span> | grep <span class="variable">$VIP</span>\`  </span><br><span class="line">        <span class="keyword">if</span> \[ ! <span class="string">"<span class="variable">$islothere</span>"</span> -o ! <span class="string">"isrothere"</span> \];then  </span><br><span class="line">            # Either the<span class="built_in"> route </span><span class="keyword">or</span> the lo:0 device  </span><br><span class="line">            # <span class="keyword">not</span> found.  </span><br><span class="line">            echo <span class="string">"LVS-DR real server Stopped."</span>  </span><br><span class="line">        <span class="keyword">else</span>  </span><br><span class="line">           echo <span class="string">"LVS-DR real server Running."</span>  </span><br><span class="line">        fi  </span><br><span class="line">;;  </span><br><span class="line">*)  </span><br><span class="line">            # Invalid entry.  </span><br><span class="line">            echo <span class="string">"<span class="variable">$0</span>: Usage: <span class="variable">$0</span> &#123;start|status|stop&#125;"</span>  </span><br><span class="line">            exit 1  </span><br><span class="line"></span><br><span class="line">;;  </span><br><span class="line">esac</span><br><span class="line">\[root@node1 ~\]# chmod +x script/realserver.sh</span><br><span class="line">\[root@node1 ~\]# ./script/realserver.sh start</span><br></pre></td></tr></table></figure></p>
<p>#-&gt;将该脚本scp到node2节点执行./script/realserver.sh start即可</p>
<p>#-&gt;如果服务器重启，那还需要手动的去执行这个脚本，服务便不可使用了，所以可以将realserver.sh加入到开机启动项中;<br><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">\[root@node1 ~\]# vim /etc/rc.local</span><br><span class="line">/bin/bash /root/script/realserver.sh start</span><br><span class="line">\[root@node1 ~\]# scp /script/realserver 192.168.254.46:/root/script</span><br><span class="line"><span class="section">#-&gt;效果如下：</span></span><br><span class="line">[<span class="string">![2</span>](<span class="link">https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/2.png</span>)](<span class="link">https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/2.png</span>) [<span class="string">![3</span>](<span class="link">https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/3.png</span>)](<span class="link">https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/3.png</span>)</span><br><span class="line"><span class="section">#-&gt;客户端访问测试：</span></span><br><span class="line">[<span class="string">![4</span>](<span class="link">https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/4.png</span>)](<span class="link">https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/4.png</span>)</span><br></pre></td></tr></table></figure></p>
<p><strong>三、**</strong>LVS-DR-Master/Slave<strong>**安装配置：</strong> <strong>3.1.master/slave**</strong>都安装<strong><strong>keepalived</strong></strong>和<strong>**ipvsadm :</strong><br><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">master</span>:</span><br><span class="line">\[root<span class="variable">@master</span> ~\]# yum install -y ipvsadm keepalived</span><br><span class="line">\[root<span class="variable">@master</span> ~\]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak  #-&gt;修改配置文件之前最好将该配置文件备份。避免后续出现问题</span><br><span class="line"><span class="attribute">Slave</span>:</span><br><span class="line">\[root<span class="variable">@slave</span> ~\]# yum install -y ipvsadm keepalived</span><br><span class="line">\[root<span class="variable">@slave</span> ~\]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak</span><br><span class="line"></span><br><span class="line">**<span class="number">3.2</span>.****在****Lvs-DR-Master****上面的配置：**</span><br><span class="line"></span><br><span class="line">\[root<span class="variable">@master</span> ~\]# vim /etc/keepalived/keepalived.conf</span><br><span class="line">! Configuration File for keepalived</span><br><span class="line"></span><br><span class="line">global_defs &#123;</span><br><span class="line">   notification_email &#123;</span><br><span class="line">    <span class="number">2399447849</span><span class="variable">@qq</span>.com               #-&gt;#设置报警邮件地址，可以设置多个，每行一个</span><br><span class="line">   &#125;</span><br><span class="line">   <span class="selector-tag">notification</span>\<span class="selector-tag">_email</span>\<span class="selector-tag">_from</span> <span class="selector-tag">root</span>@<span class="selector-tag">localhost</span><span class="selector-class">.localdomain</span></span><br><span class="line">   <span class="selector-tag">smtp_server</span> <span class="selector-tag">127</span><span class="selector-class">.0</span><span class="selector-class">.0</span><span class="selector-class">.1</span>            <span class="selector-id">#-</span>&gt;设置<span class="selector-tag">smtp</span> <span class="selector-tag">server</span>的地址</span><br><span class="line">   <span class="selector-tag">smtp</span>\<span class="selector-tag">_connect</span>\<span class="selector-tag">_timeout</span> <span class="selector-tag">30</span>          <span class="selector-id">#-</span>&gt;设置连接<span class="selector-tag">smtp</span> <span class="selector-tag">server</span>的超时时间</span><br><span class="line">   <span class="selector-tag">router</span>\<span class="selector-tag">_id</span> <span class="selector-tag">LVS</span>\<span class="selector-tag">_DEVEL</span>              <span class="selector-id">#-</span>&gt;表示运行<span class="selector-tag">keepalived</span>服务器的一个标识。发邮件时显示在邮件主题的信息</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">vrrp</span>\<span class="selector-tag">_instance</span> <span class="selector-tag">VI</span>\<span class="selector-tag">_1</span> &#123;</span><br><span class="line">    <span class="selector-tag">state</span> <span class="selector-tag">MASTER</span>           <span class="selector-id">#-</span>&gt;指定<span class="selector-tag">keepalived</span>的角色，<span class="selector-tag">MASTER</span>表示此主机是主服务器，<span class="selector-tag">BACKUP</span>表示此主机是备用服务器</span><br><span class="line">    <span class="selector-tag">interface</span> <span class="selector-tag">eth0</span>         <span class="selector-id">#-</span>&gt;指定<span class="selector-tag">HA</span>监测网络的接口</span><br><span class="line">    <span class="selector-tag">virtual</span>\<span class="selector-tag">_router</span>\<span class="selector-tag">_id</span> <span class="selector-tag">60</span>  <span class="selector-id">#-</span>&gt;虚拟路由标识，这个标识是一个数字,同一个<span class="selector-tag">vrrp</span>实例使用唯一的标识。即同一<span class="selector-tag">vrrp_instance</span>下,<span class="selector-tag">MASTER</span>和<span class="selector-tag">BACKUP</span>&gt;必须是一致的</span><br><span class="line">    <span class="selector-tag">priority</span> <span class="selector-tag">101</span>          <span class="selector-id">#-</span>&gt;定义优先级，数字越大，优先级越高，在同一个<span class="selector-tag">vrrp_instance</span>下，<span class="selector-tag">MASTER</span>的优先级必须大于<span class="selector-tag">BACKUP</span>的优先级</span><br><span class="line">    <span class="selector-tag">advert_int</span> <span class="selector-tag">1</span>          <span class="selector-id">#-</span>&gt;设定<span class="selector-tag">MASTER</span>与<span class="selector-tag">BACKUP</span>负载均衡器之间同步检查的时间间隔，单位是秒</span><br><span class="line">    <span class="selector-tag">authentication</span> &#123;      <span class="selector-id">#-</span>&gt;设置验证类型和密码</span><br><span class="line">        <span class="selector-tag">auth_type</span> <span class="selector-tag">PASS</span>    <span class="selector-id">#-</span>&gt;设置验证类型，主要有<span class="selector-tag">PASS</span>和<span class="selector-tag">AH</span>两种</span><br><span class="line">        <span class="selector-tag">auth</span>\<span class="selector-tag">_pass</span> <span class="selector-tag">1111</span>    <span class="selector-id">#-</span>&gt;设置验证密码，在同一个<span class="selector-tag">vrrp</span>\<span class="selector-tag">_instance</span>下，<span class="selector-tag">MASTER</span>与<span class="selector-tag">BACKUP</span>必须使用相同的密码才能正常通信</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">    <span class="selector-tag">virtual_ipaddress</span> &#123;   <span class="selector-id">#-</span>&gt;设置虚拟<span class="selector-tag">IP</span>地址，可以设置多个虚拟<span class="selector-tag">IP</span>地址，每行一个</span><br><span class="line">        <span class="selector-tag">192</span><span class="selector-class">.168</span><span class="selector-class">.254</span><span class="selector-class">.200</span>   <span class="selector-id">#-</span>&gt;客户端通过访问的就是该<span class="selector-tag">IP</span>地址</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">virtual_server</span> <span class="selector-tag">192</span><span class="selector-class">.168</span><span class="selector-class">.254</span><span class="selector-class">.200</span> <span class="selector-tag">80</span> &#123;  <span class="selector-id">#-</span>&gt;设置虚拟服务器，需要指定虚拟<span class="selector-tag">IP</span>地址和服务端口，<span class="selector-tag">IP</span>与端口之间用空格隔开</span><br><span class="line">    <span class="selector-tag">delay_loop</span> <span class="selector-tag">6</span>                       <span class="selector-id">#-</span>&gt;设置运行情况检查时间，单位是秒</span><br><span class="line">    <span class="selector-tag">lb_algo</span> <span class="selector-tag">rr</span>                          <span class="selector-id">#-</span>&gt;设置负载调度算法，这里设置为<span class="selector-tag">rr</span>，即轮询算法</span><br><span class="line">    <span class="selector-tag">lb_kind</span> <span class="selector-tag">DR</span>                          <span class="selector-id">#-</span>&gt;设置<span class="selector-tag">LVS</span>实现负载均衡的机制，有<span class="selector-tag">NAT</span>、<span class="selector-tag">TUN</span>、<span class="selector-tag">DR</span>三个模式可选</span><br><span class="line"><span class="selector-tag">nat_mask</span> <span class="selector-tag">255</span><span class="selector-class">.255</span><span class="selector-class">.255</span><span class="selector-class">.0</span></span><br><span class="line"><span class="selector-id">#persistence_timeout</span> <span class="selector-tag">50</span>      <span class="selector-id">#-</span>&gt;会话保持时间，单位是秒。这个选项对动态网页是非常有用的，为集群系统中的<span class="selector-tag">session</span>共享提供了一个很好&gt;的解决方案。</span><br><span class="line">                               <span class="selector-id">#-</span>&gt;有了这个会话保持功能，用户的请求会被一直分发到某个服务节点，直到超过这个会话的保持时间。</span><br><span class="line">                               <span class="selector-id">#-</span>&gt;需要注意的是，这个会话保持时间是最大无响应超时时间，也就是说，用户在操作动态页面时，如果<span class="selector-tag">50</span>秒内没</span><br><span class="line">有执行任何操作，</span><br><span class="line">    <span class="selector-tag">protocol</span> <span class="selector-tag">TCP</span>                  <span class="selector-id">#-</span>&gt;指定转发协议类型，有<span class="selector-tag">TCP</span>和<span class="selector-tag">UDP</span>两种</span><br><span class="line">    <span class="selector-tag">real_server</span> <span class="selector-tag">192</span><span class="selector-class">.168</span><span class="selector-class">.254</span><span class="selector-class">.45</span> <span class="selector-tag">80</span>  &#123;     <span class="selector-id">#-</span>&gt;配置服务节点<span class="selector-tag">1</span>，需要指定<span class="selector-tag">real</span> <span class="selector-tag">server</span>的真实<span class="selector-tag">IP</span>地址和端口，<span class="selector-tag">IP</span>与端口之间用空格隔开</span><br><span class="line">        <span class="selector-tag">weight</span> <span class="selector-tag">1</span>                           <span class="selector-id">#-</span>&gt;配置服务节点的权值，权值大小用数字表示，数字越大，权值越高，设置权值大小可以为不同性能的服务器</span><br><span class="line">                                            <span class="selector-id">#-</span>&gt;分配不同的负载，可以为性能高的服务器设置较高的权值，而为性能较低的服务器设置相对较低的权值，这样</span><br><span class="line">才能合理地利用和分配系统资源</span><br><span class="line">        <span class="selector-tag">HTTP_GET</span> &#123;                         <span class="selector-id">#-</span>&gt;<span class="selector-tag">realserver</span>的状态检测设置部分，单位是秒</span><br><span class="line">            <span class="selector-tag">url</span> &#123;                         </span><br><span class="line">              <span class="selector-tag">path</span> /</span><br><span class="line">               <span class="selector-tag">status_code</span> <span class="selector-tag">200</span>            <span class="selector-id">#-</span>&gt;状态码定义</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="selector-tag">connect_timeout</span> <span class="selector-tag">3</span>             <span class="selector-id">#-</span>&gt;表示<span class="selector-tag">3</span>秒无响应超时</span><br><span class="line">            <span class="selector-tag">nb</span>\<span class="selector-tag">_get</span>\<span class="selector-tag">_retry</span> <span class="selector-tag">3</span>                <span class="selector-id">#-</span>&gt;表示重试次数</span><br><span class="line">            <span class="selector-tag">delay</span>\<span class="selector-tag">_before</span>\<span class="selector-tag">_retry</span> <span class="selector-tag">3</span>         <span class="selector-id">#-</span>&gt;表示重试间隔</span><br><span class="line">                  &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="selector-tag">real_server</span> <span class="selector-tag">192</span><span class="selector-class">.168</span><span class="selector-class">.254</span><span class="selector-class">.46</span> <span class="selector-tag">80</span> &#123;</span><br><span class="line">        <span class="selector-tag">weight</span> <span class="selector-tag">1</span></span><br><span class="line">        <span class="selector-tag">HTTP_GET</span> &#123;</span><br><span class="line">            <span class="selector-tag">url</span> &#123;</span><br><span class="line">              <span class="selector-tag">path</span> /</span><br><span class="line">               <span class="selector-tag">status_code</span> <span class="selector-tag">200</span></span><br><span class="line">           &#125;</span><br><span class="line">            <span class="selector-tag">connect_timeout</span> <span class="selector-tag">3</span></span><br><span class="line">            <span class="selector-tag">nb</span>\<span class="selector-tag">_get</span>\<span class="selector-tag">_retry</span> <span class="selector-tag">3</span></span><br><span class="line">            <span class="selector-tag">delay</span>\<span class="selector-tag">_before</span>\<span class="selector-tag">_retry</span> <span class="selector-tag">3</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>#-&gt;根据实验的拓扑可知后端的realserver有两台，所以上面定义了两个realserver的配置</p>
<p><strong>3.3**</strong>在<strong><strong>Lvs-DR-Slave</strong></strong>上面的配置：**</p>
<p>[root@master ~]# scp /etc/keepalived/keepalived.conf 192.168.254.48:/etc/keepalived/  #-&gt;将master上面的配置复制至slave,然后稍作修改：<br>[root@slave ~]# vim /etc/keepalived/keepalived.conf</p>
<p>#-&gt;配置文件各个参数上面以解释，这里只对需要修改的作说明：<br><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line">! Configuration File for keepalived</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">global_defs &#123;</span><br><span class="line">   notification_email &#123;</span><br><span class="line">    <span class="number">2399447849</span>@qq.com</span><br><span class="line">   &#125;</span><br><span class="line">   notification\_email\_from root</span><br><span class="line">   smtp_server <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">   smtp\_connect\_timeout <span class="number">30</span></span><br><span class="line">   router\_id LVS\_DEVEL</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">vrrp\_instance VI\_1 &#123;</span><br><span class="line">    <span class="section">state</span> BACKUP               #-&gt;指定该服务器的keepalived角色为BACKUP(备用服务器)</span><br><span class="line">    interface eth0</span><br><span class="line">    virtual\_router\_id <span class="number">60</span>     </span><br><span class="line">    priority <span class="number">100</span>               #-&gt;在同一个vrrp_instance下，MASTER的优先级必须大于BACKUP的优先级</span><br><span class="line">    advert_int <span class="number">1</span></span><br><span class="line">    authentication &#123;</span><br><span class="line">        auth_type PASS</span><br><span class="line">        auth_pass <span class="number">1111</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    virtual_ipaddress &#123;</span><br><span class="line">        <span class="number">192.168</span><span class="number">.254</span><span class="number">.200</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">virtual_server <span class="number">192.168</span><span class="number">.254</span><span class="number">.200</span> <span class="number">80</span> &#123;</span><br><span class="line">    delay_loop <span class="number">6</span></span><br><span class="line">    lb_algo rr</span><br><span class="line">    lb_kind DR</span><br><span class="line">   nat_mask <span class="number">255.255</span><span class="number">.255</span><span class="number">.0</span></span><br><span class="line">    #persistence_timeout <span class="number">50</span></span><br><span class="line">protocol TCP</span><br><span class="line">   real_server <span class="number">192.168</span><span class="number">.254</span><span class="number">.45</span> <span class="number">80</span>  &#123;</span><br><span class="line">        weight <span class="number">1</span></span><br><span class="line">        HTTP_GET &#123;</span><br><span class="line">            url &#123;</span><br><span class="line">              path /</span><br><span class="line">               status_code <span class="number">200</span></span><br><span class="line">            &#125;</span><br><span class="line">            connect_timeout <span class="number">3</span></span><br><span class="line">            nb\_get\_retry <span class="number">3</span></span><br><span class="line">            delay\_before\_retry <span class="number">3</span></span><br><span class="line">                 &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    real_server <span class="number">192.168</span><span class="number">.254</span><span class="number">.46</span> <span class="number">80</span> &#123;</span><br><span class="line">        weight <span class="number">1</span></span><br><span class="line">        HTTP_GET &#123;</span><br><span class="line">            url &#123;</span><br><span class="line">             path /</span><br><span class="line">              status_code <span class="number">200</span></span><br><span class="line">            &#125;</span><br><span class="line">            connect_timeout <span class="number">3</span></span><br><span class="line">            nb\_get\_retry <span class="number">3</span></span><br><span class="line">            delay\_before\_retry <span class="number">3</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><strong>3.4.**</strong>启动<strong><strong>keepalived (</strong></strong>启动过程中观察日志<strong>**)</strong><br><figure class="highlight livescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br></pre></td><td class="code"><pre><span class="line">master:</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> service keepalived start &amp;&amp; tail -f /<span class="keyword">var</span>/log/messages</span><br><span class="line">...........</span><br><span class="line">...........</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">14</span> master Keepalived_healthcheckers<span class="string">\[31358\]:</span> Opening file <span class="string">'/etc/keepalived/keepalived.conf'</span>.</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">14</span> master Keepalived_healthcheckers<span class="string">\[31358\]:</span> Configuration <span class="keyword">is</span> using : <span class="number">16384</span> Bytes</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">14</span> master Keepalived_healthcheckers<span class="string">\[31358\]:</span> Using LinkWatch kernel netlink reflector...</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">14</span> master Keepalived_healthcheckers<span class="string">\[31358\]:</span> Activating healthchecker <span class="keyword">for</span> service <span class="string">\[192.168.254.45\]:80</span></span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">14</span> master Keepalived_healthcheckers<span class="string">\[31358\]:</span> Activating healthchecker <span class="keyword">for</span> service <span class="string">\[192.168.254.46\]:80</span></span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">15</span> master Keepalived<span class="string">\_vrrp\[31359\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> Transition <span class="keyword">to</span> MASTER STATE</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">16</span> master Keepalived<span class="string">\_vrrp\[31359\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> Entering MASTER STATE  <span class="comment">#-&gt;主服务器状态</span></span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">16</span> master Keepalived<span class="string">\_vrrp\[31359\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> setting protocol VIPs.</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">16</span> master Keepalived<span class="string">\_vrrp\[31359\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> Sending gratuitous ARPs <span class="literal">on</span> eth0 <span class="keyword">for</span> <span class="number">192.168</span>.<span class="number">254.200</span></span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">16</span> master Keepalived_healthcheckers<span class="string">\[31358\]:</span> Netlink reflector reports IP <span class="number">192.168</span>.<span class="number">254.200</span> added</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">21</span> master Keepalived<span class="string">\_vrrp\[31359\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> Sending gratuitous ARPs <span class="literal">on</span> eth0 <span class="keyword">for</span> <span class="number">192.168</span>.<span class="number">254.200</span></span><br><span class="line">...........</span><br><span class="line">...........</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> ipvsadm -L –n       <span class="comment">#-&gt;LVS状态</span></span><br><span class="line">IP Virtual Server version <span class="number">1.2</span>.<span class="number">1</span> (size=<span class="number">4096</span>)</span><br><span class="line">Prot LocalAddress:Port Scheduler Flags</span><br><span class="line">  -<span class="string">\&gt;</span> RemoteAddress:Port           Forward Weight ActiveConn InActConn</span><br><span class="line">TCP  <span class="number">192.168</span>.<span class="number">254.200</span>:<span class="number">80</span> rr</span><br><span class="line">  -<span class="string">\&gt;</span> <span class="number">192.168</span>.<span class="number">254.45</span>:<span class="number">80</span>            Route   <span class="number">1</span>      <span class="number">0</span>          <span class="number">0</span>        </span><br><span class="line">  -<span class="string">\&gt;</span> <span class="number">192.168</span>.<span class="number">254.46</span>:<span class="number">80</span>            Route   <span class="number">1</span>      <span class="number">0</span>          <span class="number">0</span>        </span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> ip a</span><br><span class="line"><span class="number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="number">16436</span> qdisc noqueue state UNKNOWN</span><br><span class="line">    link/loopback <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> brd <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span></span><br><span class="line">    inet <span class="number">127.0</span>.<span class="number">0.1</span>/<span class="number">8</span> scope host lo</span><br><span class="line">    inet6 ::<span class="number">1</span>/<span class="number">128</span> scope host</span><br><span class="line">       valid<span class="string">\_lft</span> forever preferred<span class="string">\_lft</span> forever</span><br><span class="line"><span class="number">2</span>: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER<span class="string">\_UP&gt;</span> mtu <span class="number">1500</span> qdisc pfifo<span class="string">\_fast</span> state UP qlen <span class="number">1000</span></span><br><span class="line">   link/ether <span class="number">00</span>:<span class="number">0c</span>:<span class="number">29</span>:<span class="number">5d</span>:<span class="number">7d</span>:<span class="number">94</span> brd ff:ff:ff:ff:ff:ff</span><br><span class="line">    inet <span class="number">192.168</span>.<span class="number">254.47</span>/<span class="number">24</span> brd <span class="number">192.168</span>.<span class="number">254.255</span> scope <span class="built_in">global</span> eth0</span><br><span class="line">    inet <span class="number">192.168</span>.<span class="number">254.200</span>/<span class="number">32</span> scope <span class="built_in">global</span> eth0    <span class="comment">#-&gt;此时VIP在master上面</span></span><br><span class="line">    inet6 fe80::<span class="number">20c</span>:<span class="number">29ff</span>:fe5d:<span class="number">7d</span>94/<span class="number">64</span> scope link</span><br><span class="line">       valid<span class="string">\_lft</span> forever preferred<span class="string">\_lft</span> forever</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span></span><br><span class="line">Slave:</span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> service keepalived start &amp;&amp; tail -f /<span class="keyword">var</span>/log/messages</span><br><span class="line">...........</span><br><span class="line">...........</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_vrrp<span class="string">\[31389\]:</span> Opening file <span class="string">'/etc/keepalived/keepalived.conf'</span>.</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_vrrp<span class="string">\[31389\]:</span> Configuration <span class="keyword">is</span> using : <span class="number">62845</span> Bytes</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_vrrp<span class="string">\[31389\]:</span> Using LinkWatch kernel netlink reflector...</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived<span class="string">\_vrrp\[31389\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> Entering BACKUP STATE  <span class="comment">#-&gt;备用服务器状态</span></span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_vrrp<span class="string">\[31389\]:</span> VRRP sockpool: <span class="string">\[ifindex(2),</span> proto(<span class="number">112</span>), fd(<span class="number">10</span>,<span class="number">11</span>)<span class="string">\]</span></span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_healthcheckers<span class="string">\[31388\]:</span> Opening file <span class="string">'/etc/keepalived/keepalived.conf'</span>.</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_healthcheckers<span class="string">\[31388\]:</span> Configuration <span class="keyword">is</span> using : <span class="number">16384</span> Bytes</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_healthcheckers<span class="string">\[31388\]:</span> Using LinkWatch kernel netlink reflector...</span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_healthcheckers<span class="string">\[31388\]:</span> Activating healthchecker <span class="keyword">for</span> service <span class="string">\[192.168.254.45\]:80</span></span><br><span class="line">Oct <span class="number">29</span> <span class="number">21</span>:<span class="number">42</span>:<span class="number">34</span> slave Keepalived_healthcheckers<span class="string">\[31388\]:</span> Activating healthchecker <span class="keyword">for</span> service <span class="string">\[192.168.254.46\]:80</span></span><br><span class="line">...........</span><br><span class="line">...........</span><br><span class="line"></span><br><span class="line">**<span class="number">3.5</span>.****测试：** [![<span class="number">5</span>](https:<span class="regexp">//raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/5.png)](https://</span>raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/<span class="number">2014</span>/<span class="number">10</span>/<span class="number">5.png</span>) **<span class="number">3.6</span>.****模拟故障**： (<span class="number">1</span>)停掉node1节点的web服务：</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@node1</span> ~<span class="string">\]#</span> service httpd stop</span><br><span class="line">停止 httpd：                                               <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@node1</span> ~<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">(<span class="number">2</span>)查看一下报警邮件： [![<span class="number">6</span>](https:<span class="regexp">//raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/6.png)](https://</span>raw.githubusercontent.com<span class="regexp">/guomaoqiu/myblog_backup/master/uploads/2014/10/6.png) (3)再在前端调度器上查看一下LVS状态： [![7](https:/</span><span class="regexp">/raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/7.png)](https:/</span>/raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/<span class="number">2014</span>/<span class="number">10</span>/<span class="number">7.png</span>) 很明显那台出现问题的realserver条目已经被剔除了 (<span class="number">4</span>)恢复node1节点上的web服务：</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@node1</span> ~<span class="string">\]#</span> service httpd start</span><br><span class="line">启动 httpd：                                               <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@node1</span> ~<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">(<span class="number">5</span>) 查看一下报警邮件： [![<span class="number">8</span>](https:<span class="regexp">//raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/8.png)](https://</span>raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/<span class="number">2014</span>/<span class="number">10</span>/<span class="number">8.png</span>) (<span class="number">6</span>)关闭master上面的keepalived：</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> service keepalived stop</span><br><span class="line">停止 keepalived：                                          <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> ipvsadm -L -n</span><br><span class="line">IP Virtual Server version <span class="number">1.2</span>.<span class="number">1</span> (size=<span class="number">4096</span>)</span><br><span class="line">Prot LocalAddress:Port Scheduler Flags</span><br><span class="line">  -<span class="string">\&gt;</span> RemoteAddress:Port           Forward Weight ActiveConn InActConn</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">(<span class="number">7</span>)查看slave状态：</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> ip a</span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line">    inet <span class="number">192.168</span>.<span class="number">254.200</span>/<span class="number">32</span> scope <span class="built_in">global</span> eth0     <span class="comment">#-&gt;可见VIP已经转移到了slave上面；并且通过客户端访问仍然正常！</span></span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line"> <span class="string">\[root@slave</span> ~<span class="string">\]#</span> ipvsadm -L -n</span><br><span class="line">IP Virtual Server version <span class="number">1.2</span>.<span class="number">1</span> (size=<span class="number">4096</span>)</span><br><span class="line"></span><br><span class="line">Prot LocalAddress:Port Scheduler Flags</span><br><span class="line"></span><br><span class="line">  -<span class="string">\&gt;</span> RemoteAddress:Port           Forward Weight ActiveConn InActConn</span><br><span class="line"></span><br><span class="line">TCP  <span class="number">192.168</span>.<span class="number">254.200</span>:<span class="number">80</span> rr</span><br><span class="line">  -<span class="string">\&gt;</span> <span class="number">192.168</span>.<span class="number">254.45</span>:<span class="number">80</span>            Route   <span class="number">1</span>      <span class="number">0</span>          <span class="number">0</span>        </span><br><span class="line">  -<span class="string">\&gt;</span> <span class="number">192.168</span>.<span class="number">254.46</span>:<span class="number">80</span>            Route   <span class="number">1</span>      <span class="number">0</span>          <span class="number">0</span>        </span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">**通过上面的演示现在的****LVS****的高可用即前端负载均衡调度器的高可用，同时实现了对后端****realserver****监控，也实现了后端****realserver****宕机时会给管理员发送邮件；但是目前还面临几个问题：**</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span>  **如果所有的****realserver****都宕机，如何处理，用户打不开就等它打不开，还是友善的提示一下？**</span><br><span class="line"><span class="number">2.</span>  **怎么完成维护模式****keepalived****切换？**</span><br><span class="line"><span class="number">3.</span>  **如何在****keepalived****主备切换时向管理员发送邮件？**</span><br><span class="line"></span><br><span class="line">**四、****LVS+Keepalived****后续延伸：** **<span class="number">4.1</span>.****所有****realserver****都宕机如何处理？** 在集群中如果所有real server全部宕机了，客户端访问时就会出现错误页面，这样是很不友好的，我们得提供一个维护页面来提醒用户，服务器正在维护，什么时间可以访问等，下面就来解决一下这个问题。解决方案有两种，一种是提供一台备用的real server当所有的服务器宕机时，提供维护页面，但这样做有点浪费服务器。另一种就是在负载均衡器上提供维护页面，这样是比较靠谱的，也比较常用。下面就来具体操作一下。 (<span class="number">1</span>)在master和slave上面安装httpd</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> yum install -y httpd</span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> yum install -y httpd</span><br><span class="line"></span><br><span class="line">(<span class="number">2</span>)提供维护页面文件</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> echo <span class="string">"Oops ... you visit the page does not exist, the server may be maintained?"</span> &gt; /<span class="keyword">var</span>/www/html/index.html</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> service httpd start</span><br><span class="line">启动 httpd：                                               <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> echo <span class="string">"Oops ... you visit the page does not exist, the server may be maintained?"</span> &gt; /<span class="keyword">var</span>/www/html/index.html</span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> service httpd start</span><br><span class="line">启动 httpd：                                               <span class="string">\[确定\]</span></span><br><span class="line"></span><br><span class="line">(<span class="number">3</span>)测试： [![<span class="number">9</span>](https:<span class="regexp">//raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/9.png)](https://</span>raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/<span class="number">2014</span>/<span class="number">10</span>/<span class="number">9.png</span>) (<span class="number">4</span>)修改master/slave的keepalived配置文件：</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> vim /etc/keepalived/keepalived.conf</span><br><span class="line">! Configuration File <span class="keyword">for</span> keepalived</span><br><span class="line"></span><br><span class="line">global_defs &#123;</span><br><span class="line">notification_email &#123;</span><br><span class="line"><span class="number">2399447849</span>@qq.com</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">notification<span class="string">\_email\_from</span> root</span><br><span class="line">smtp_server <span class="number">127.0</span>.<span class="number">0.1</span></span><br><span class="line">smtp<span class="string">\_connect\_timeout</span> <span class="number">30</span></span><br><span class="line">router<span class="string">\_id</span> LVS<span class="string">\_DEVEL</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">vrrp<span class="string">\_instance</span> VI<span class="string">\_1</span> &#123;</span><br><span class="line">state MASTER</span><br><span class="line">interface eth0</span><br><span class="line">       virtual<span class="string">\_router\_id</span> <span class="number">60</span></span><br><span class="line">       priority <span class="number">101</span></span><br><span class="line">       advert_int <span class="number">1</span></span><br><span class="line">      authentication &#123;</span><br><span class="line">       auth_type PASS</span><br><span class="line">      auth_pass <span class="number">1111</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">virtual_ipaddress &#123;</span><br><span class="line">     <span class="number">192.168</span>.<span class="number">254.200</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">virtual_server <span class="number">192.168</span>.<span class="number">254.200</span> <span class="number">80</span> &#123;</span><br><span class="line">delay_loop <span class="number">6</span></span><br><span class="line">lb_algo rr</span><br><span class="line">lb_kind DR</span><br><span class="line">nat_mask <span class="number">255.255</span>.<span class="number">255.0</span></span><br><span class="line"><span class="comment">#persistence_timeout 50</span></span><br><span class="line">protocol TCP</span><br><span class="line"></span><br><span class="line">real_server <span class="number">192.168</span>.<span class="number">254.45</span> <span class="number">80</span>&amp;nbsp; &#123;</span><br><span class="line">weight <span class="number">1</span></span><br><span class="line">HTTP_GET &#123;</span><br><span class="line"></span><br><span class="line">  url &#123;</span><br><span class="line">   path /</span><br><span class="line">   status_code <span class="number">200</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">connect_timeout <span class="number">3</span></span><br><span class="line">nb<span class="string">\_get\_retry</span> <span class="number">3</span></span><br><span class="line">delay<span class="string">\_before\_retry</span> <span class="number">3</span></span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">real_server <span class="number">192.168</span>.<span class="number">254.46</span> <span class="number">80</span> &#123;</span><br><span class="line">weight <span class="number">1</span></span><br><span class="line">HTTP_GET &#123;</span><br><span class="line">url &#123;</span><br><span class="line">path /</span><br><span class="line">status_code <span class="number">200</span></span><br><span class="line">&#125;</span><br><span class="line">connect_timeout <span class="number">3</span></span><br><span class="line">nb<span class="string">\_get\_retry</span> <span class="number">3</span></span><br><span class="line">delay<span class="string">\_before\_retry</span> <span class="number">3</span></span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">sorry_server <span class="number">127.0</span>.<span class="number">0.1</span>&amp;nbsp;&amp;nbsp; <span class="comment">#-&gt;增加该配置参数，slave上面也需要添加，此处略。</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">(<span class="number">5</span>)关闭所有的realserver web服务,重新启动master/slave 的keepalived:  </span><br><span class="line"></span><br><span class="line">node1:</span><br><span class="line"><span class="string">\[root@node1</span> ~<span class="string">\]#</span> service httpd stop</span><br><span class="line">停止 httpd：                                               <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@node1</span> ~<span class="string">\]#</span></span><br><span class="line">node2:</span><br><span class="line"><span class="string">\[root@node2</span> ~<span class="string">\]#</span> service httpd stop</span><br><span class="line">停止 httpd：                                               <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@node2</span> ~<span class="string">\]#</span></span><br><span class="line">master:</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> service keepalived restart</span><br><span class="line">停止 keepalived：                                          <span class="string">\[确定\]</span></span><br><span class="line">正在启动 keepalived：                                      <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span></span><br><span class="line">slave:</span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> service keepalived restart</span><br><span class="line">停止 keepalived：                                          <span class="string">\[确定\]</span></span><br><span class="line">正在启动 keepalived：                                      <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">(<span class="number">6</span>)查看一下LVS状态： [![<span class="number">10</span>](https:<span class="regexp">//raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/10.png)](https://</span>raw.githubusercontent.com<span class="regexp">/guomaoqiu/myblog_backup/master/uploads/2014/10/10.png) (7)访问测试： [![11](https:/</span><span class="regexp">/raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/11.png)](https:/</span>/raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/<span class="number">2014</span>/<span class="number">10</span>/<span class="number">11.png</span>) **<span class="number">4.2</span>.****如何完成维护模式****keepalived** **切换？** 一般我们在测试主从切换的过程当中要么是手动停止keepalived服务，要么是手动关闭网卡，那还有其他方法实现维护模式的切换，这就是vrrp_script功能； (<span class="number">1</span>)master/slave配置：**(****注****:****这里演示主服务器的配置，添加上去的在****slave****上面也需要添加以红色标注内容****)**</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> vim /etc/keepalived/keepalived.conf</span><br><span class="line">! Configuration File <span class="keyword">for</span> keepalived</span><br><span class="line"></span><br><span class="line">global_defs &#123;</span><br><span class="line"></span><br><span class="line">notification_email &#123;</span><br><span class="line"><span class="number">2399447849</span>@qq.com</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">notification<span class="string">\_email\_from</span> root</span><br><span class="line">smtp_server <span class="number">127.0</span>.<span class="number">0.1</span></span><br><span class="line">smtp<span class="string">\_connect\_timeout</span> <span class="number">30</span></span><br><span class="line">router<span class="string">\_id</span> LVS<span class="string">\_DEVEL</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">vrrp<span class="string">\_script</span> chk<span class="string">\_schedown</span> &#123;       <span class="comment">#-&gt;定义vrrp执行脚本</span></span><br><span class="line">   script <span class="string">"\[ -e /etc/keepalived/down \] &amp;&amp; exit 1 || exit 0"</span>  <span class="comment">#-&gt;查看是否有down文件，有就进入维护模式</span></span><br><span class="line">   interval <span class="number">1</span>         <span class="comment">#-&gt;监控间隔时间</span></span><br><span class="line">   weight -<span class="number">5</span>          <span class="comment">#-&gt;降低优先级,即priority参数</span></span><br><span class="line">   fall <span class="number">2</span>             <span class="comment">#-&gt;失败次数</span></span><br><span class="line">   rise <span class="number">1</span>             <span class="comment">#-&gt;成功次数</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">vrrp<span class="string">\_instance</span> VI<span class="string">\_1</span> &#123;</span><br><span class="line">state MASTER</span><br><span class="line">interface eth0</span><br><span class="line">virtual<span class="string">\_router\_id</span> <span class="number">60</span></span><br><span class="line">priority <span class="number">101</span></span><br><span class="line">advert_int <span class="number">1</span></span><br><span class="line">authentication &#123;</span><br><span class="line">auth_type PASS</span><br><span class="line">auth_pass <span class="number">1111</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">virtual_ipaddress &#123;</span><br><span class="line"><span class="number">192.168</span>.<span class="number">254.200</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">track_script &#123;             <span class="comment">#-&gt;脚本追踪</span></span><br><span class="line">    chk_schedown           <span class="comment">#-&gt;上面自定义的vrrp脚本名称</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">virtual_server <span class="number">192.168</span>.<span class="number">254.200</span> <span class="number">80</span> &#123;</span><br><span class="line">delay_loop <span class="number">6</span></span><br><span class="line">lb_algo rr</span><br><span class="line">lb_kind DR</span><br><span class="line">nat_mask <span class="number">255.255</span>.<span class="number">255.0</span></span><br><span class="line"><span class="comment">#persistence_timeout 50</span></span><br><span class="line">protocol TCP</span><br><span class="line"> </span><br><span class="line">real_server <span class="number">192.168</span>.<span class="number">254.45</span> <span class="number">80</span>  &#123;</span><br><span class="line">weight <span class="number">1</span></span><br><span class="line">HTTP_GET &#123;</span><br><span class="line">url &#123;</span><br><span class="line">path /</span><br><span class="line">status_code <span class="number">200</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">connect_timeout <span class="number">3</span></span><br><span class="line">nb<span class="string">\_get\_retry</span> <span class="number">3</span></span><br><span class="line">delay<span class="string">\_before\_retry</span> <span class="number">3</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">real_server <span class="number">192.168</span>.<span class="number">254.46</span> <span class="number">80</span> &#123;</span><br><span class="line">weight <span class="number">1</span></span><br><span class="line">HTTP_GET &#123;</span><br><span class="line">url &#123;</span><br><span class="line">path /</span><br><span class="line">status_code <span class="number">200</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">connect_timeout <span class="number">3</span></span><br><span class="line">nb<span class="string">\_get\_retry</span> <span class="number">3</span></span><br><span class="line">delay<span class="string">\_before\_retry</span> <span class="number">3</span></span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">sorry_server <span class="number">127.0</span>.<span class="number">0.1</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">(<span class="number">2</span>)测试： </span><br><span class="line"></span><br><span class="line">master:</span><br><span class="line"><span class="string">\[root@master</span> keepalived<span class="string">\]#</span> touch down  <span class="comment">#-&gt;新建一个down文件，进入维护模式</span></span><br><span class="line"><span class="string">\[root@master</span> keepalived<span class="string">\]#</span> ll</span><br><span class="line">总用量 <span class="number">4</span></span><br><span class="line">-rw-r--r--. <span class="number">1</span> root root    <span class="number">0</span> <span class="number">10</span>月 <span class="number">30</span> <span class="number">00</span>:<span class="number">16</span> down</span><br><span class="line">-rw-r--r--. <span class="number">1</span> root root <span class="number">1513</span> <span class="number">10</span>月 <span class="number">30</span> <span class="number">00</span>:<span class="number">08</span> keepalived.conf</span><br><span class="line"><span class="string">\[root@master</span> keepalived<span class="string">\]#</span> tail -f /<span class="keyword">var</span>/log/messages</span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line">Oct <span class="number">30</span> <span class="number">00</span>:<span class="number">16</span>:<span class="number">43</span> node3 Keepalived<span class="string">\_vrrp\[31993\]:</span> VRRP<span class="string">\_Script(chk_schedown)</span> failed</span><br><span class="line">Oct <span class="number">30</span> <span class="number">00</span>:<span class="number">16</span>:<span class="number">44</span> node3 Keepalived<span class="string">\_vrrp\[31993\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> Received higher prio advert</span><br><span class="line">Oct <span class="number">30</span> <span class="number">00</span>:<span class="number">16</span>:<span class="number">44</span> node3 Keepalived<span class="string">\_vrrp\[31993\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> Entering BACKUP STATE</span><br><span class="line">Oct <span class="number">30</span> <span class="number">00</span>:<span class="number">16</span>:<span class="number">44</span> node3 Keepalived<span class="string">\_vrrp\[31993\]:</span> VRRP<span class="string">\_Instance(VI_1)</span> removing protocol VIPs.</span><br><span class="line">Oct <span class="number">30</span> <span class="number">00</span>:<span class="number">16</span>:<span class="number">44</span> node3 Keepalived_healthcheckers<span class="string">\[31992\]:</span> Netlink reflector reports IP <span class="number">192.168</span>.<span class="number">254.200</span> removed  <span class="comment">#-&gt;该VIP已转移到slave.</span></span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line"><span class="string">\[root@master</span> keepalived<span class="string">\]#</span> ip a   <span class="comment">#-&gt;VIP 已转移到slave</span></span><br><span class="line"><span class="number">1</span>: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu <span class="number">16436</span> qdisc noqueue state UNKNOWN</span><br><span class="line">link/loopback <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> brd <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span></span><br><span class="line">inet <span class="number">127.0</span>.<span class="number">0.1</span>/<span class="number">8</span> scope host lo</span><br><span class="line">inet6 ::<span class="number">1</span>/<span class="number">128</span> scope host</span><br><span class="line">valid<span class="string">\_lft</span> forever preferred<span class="string">\_lft</span> forever</span><br><span class="line"><span class="number">2</span>: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER<span class="string">\_UP&gt;</span> mtu <span class="number">1500</span> qdisc pfifo<span class="string">\_fast</span> state UP qlen <span class="number">1000</span></span><br><span class="line">link/ether <span class="number">00</span>:<span class="number">0c</span>:<span class="number">29</span>:<span class="number">5d</span>:<span class="number">7d</span>:<span class="number">94</span> brd ff:ff:ff:ff:ff:ff</span><br><span class="line">inet <span class="number">192.168</span>.<span class="number">254.47</span>/<span class="number">24</span> brd <span class="number">192.168</span>.<span class="number">254.255</span> scope <span class="built_in">global</span> eth0</span><br><span class="line">inet6 fe80::<span class="number">20c</span>:<span class="number">29ff</span>:fe5d:<span class="number">7d</span>94/<span class="number">64</span> scope link</span><br><span class="line">valid<span class="string">\_lft</span> forever preferred<span class="string">\_lft</span> forever</span><br><span class="line"><span class="string">\[root@master</span> keepalived<span class="string">\]#</span></span><br><span class="line">slave:</span><br><span class="line"><span class="string">\[root@slave</span> keepalived<span class="string">\]#</span> ip a</span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line">inet <span class="number">192.168</span>.<span class="number">254.200</span>/<span class="number">32</span> scope <span class="built_in">global</span> eth0   <span class="comment">#-&gt;VIP 已转移过来</span></span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line"><span class="string">\[root@slave</span> keepalived<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">  **至此自写监测脚本，完成维护模式切换，已经完成；下面来解决最后一个问题：** **<span class="number">4.3</span>.****如何在****Keepalived****主从切换时向管理员发送通知邮件？** (<span class="number">1</span>)Keepalived通知脚本进阶示例：</span><br><span class="line"></span><br><span class="line">下面的脚本可以接受选项，其中：</span><br><span class="line">-s, --service SERVICE,...：指定服务脚本名称，当状态切换时可自动启动、重启或关闭此服务；</span><br><span class="line">-a, --address VIP: 指定相关虚拟路由器的VIP地址；</span><br><span class="line">-m, --mode &#123;mm|mb&#125;：指定虚拟路由的模型，mm表示主主，mb表示主备；它们表示相对于同一种服务而方，其VIP的工作类型；</span><br><span class="line">-n, --notify &#123;master|backup|fault&#125;：指定通知的类型，即vrrp角色切换的目标角色；</span><br><span class="line">-h, --help：获取脚本的使用帮助；</span><br><span class="line"></span><br><span class="line"><span class="comment">#!/bin/bash</span></span><br><span class="line"><span class="string">\#</span> Author: Tux</span><br><span class="line"><span class="string">\#</span> description: An example <span class="keyword">of</span> notify script</span><br><span class="line"><span class="string">\#</span> Usage: notify.sh -m|--mode &#123;mm|mb&#125; -s|--service SERVICE1,... -a|--address VIP&amp;nbsp; -n|--notify &#123;master|backup|falut&#125; -h|--help</span><br><span class="line"></span><br><span class="line">&amp;nbsp;</span><br><span class="line"></span><br><span class="line">helpflag=<span class="number">0</span></span><br><span class="line">serviceflag=<span class="number">0</span></span><br><span class="line">modeflag=<span class="number">0</span></span><br><span class="line">addressflag=<span class="number">0</span></span><br><span class="line">notifyflag=<span class="number">0</span></span><br><span class="line"></span><br><span class="line">contact=<span class="string">'2399447849@qq.com'</span>&amp;nbsp;&amp;nbsp; <span class="comment">#-&gt;指定联系人;可以有多个，用”,”分隔开来</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&lt;br&gt;</span><br><span class="line">Usage() &#123;</span><br><span class="line">  echo <span class="string">"Usage: notify.sh \[-m|--mode &#123;mm|mb&#125;\] \[-s|--service SERVICE1,...\] &lt;-a|--address VIP&gt;  &lt;-n|--notify &#123;master|backup|falut&#125;&gt;"</span> </span><br><span class="line">  echo <span class="string">"Usage: notify.sh -h|--help"</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">########################################################################################</span></span><br><span class="line">ParseOptions() &#123;</span><br><span class="line">  local I=<span class="number">1</span>;</span><br><span class="line">  <span class="keyword">if</span> <span class="string">\[</span> $<span class="comment"># -gt 0 \]; then</span></span><br><span class="line">    <span class="keyword">while</span> <span class="string">\[</span> $I -le $<span class="comment"># \]; do</span></span><br><span class="line">      <span class="keyword">case</span> $<span class="number">1</span> <span class="keyword">in</span></span><br><span class="line">	  -s|--service)</span><br><span class="line">		<span class="string">\[</span> $<span class="comment"># -lt 2 \] &amp;&amp; return 3</span></span><br><span class="line"> 	    serviceflag=<span class="number">1</span></span><br><span class="line"> 		services=(<span class="string">\`echo</span> $<span class="number">2</span>|awk -F<span class="string">","</span> <span class="string">'&#123;for(i=1;i&lt;=NF;i++) print $i&#125;'</span><span class="string">\`)</span></span><br><span class="line">		shift <span class="number">2</span> ;;</span><br><span class="line">	  -h|--help)</span><br><span class="line"> 		helpflag=<span class="number">1</span></span><br><span class="line">		<span class="keyword">return</span> <span class="number">0</span></span><br><span class="line">        shift</span><br><span class="line">		;;</span><br><span class="line">	  -a|--address)</span><br><span class="line">		<span class="string">\[</span> $<span class="comment"># -lt 2 \] &amp;&amp; return 3</span></span><br><span class="line">	    addressflag=<span class="number">1</span></span><br><span class="line">		vip=$<span class="number">2</span></span><br><span class="line">		shift <span class="number">2</span></span><br><span class="line">		;;</span><br><span class="line">	  -m|--mode)</span><br><span class="line">		<span class="string">\[</span> $<span class="comment"># -lt 2 \] &amp;&amp; return 3</span></span><br><span class="line">		mode=$<span class="number">2</span></span><br><span class="line">		shift <span class="number">2</span></span><br><span class="line">		;;</span><br><span class="line">	  -n|--notify)</span><br><span class="line">		<span class="string">\[</span> $<span class="comment"># -lt 2 \] &amp;&amp; return 3</span></span><br><span class="line">		notifyflag=<span class="number">1</span></span><br><span class="line">		notify=$<span class="number">2</span></span><br><span class="line">		shift <span class="number">2</span></span><br><span class="line">		;;</span><br><span class="line">	  *)</span><br><span class="line">		echo <span class="string">"Wrong options..."</span></span><br><span class="line">		Usage</span><br><span class="line">		<span class="keyword">return</span> <span class="number">7</span></span><br><span class="line">		;;</span><br><span class="line">       esac</span><br><span class="line">    done</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">#workspace=$(dirname $0)</span></span><br><span class="line"></span><br><span class="line">RestartService() &#123;</span><br><span class="line">  <span class="keyword">if</span> <span class="string">\[</span> $&#123;<span class="comment">#@&#125; -gt 0 \]; then</span></span><br><span class="line">    <span class="keyword">for</span> I <span class="keyword">in</span> $@; <span class="keyword">do</span></span><br><span class="line">      <span class="keyword">if</span> <span class="string">\[</span> -x <span class="regexp">/etc/rc.d/init.d/</span>$I <span class="string">\];</span> <span class="keyword">then</span></span><br><span class="line">        <span class="regexp">/etc/rc.d/init.d/</span>$I restart</span><br><span class="line">      <span class="keyword">else</span></span><br><span class="line">        echo <span class="string">"$I is not a valid service..."</span></span><br><span class="line">      fi</span><br><span class="line">    done</span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">StopService() &#123;</span><br><span class="line">  <span class="keyword">if</span> <span class="string">\[</span> $&#123;<span class="comment">#@&#125; -gt 0 \]; then</span></span><br><span class="line">    <span class="keyword">for</span> I <span class="keyword">in</span> $@; <span class="keyword">do</span></span><br><span class="line">      <span class="keyword">if</span> <span class="string">\[</span> -x <span class="regexp">/etc/rc.d/init.d/</span>$I <span class="string">\];</span> <span class="keyword">then</span></span><br><span class="line">        <span class="regexp">/etc/rc.d/init.d/</span>$I stop</span><br><span class="line">      <span class="keyword">else</span></span><br><span class="line">        echo <span class="string">"$I is not a valid service..."</span></span><br><span class="line">      fi</span><br><span class="line">    done</span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Notify() &#123;</span><br><span class="line">    mailsubject=<span class="string">"\`hostname\` to be $1: $vip floating"</span></span><br><span class="line">    mailbody=<span class="string">"\`date '+%F %H:%M:%S'\`, vrrp transition, \`hostname\` changed to be $1."</span></span><br><span class="line">    echo $mailbody | mail -s <span class="string">"$mailsubject"</span> $contact</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="string">\#</span> Main Function</span><br><span class="line">ParseOptions $@</span><br><span class="line"><span class="string">\[</span> $? -ne <span class="number">0</span> <span class="string">\]</span> &amp;&amp; Usage &amp;&amp; exit <span class="number">5</span></span><br><span class="line"></span><br><span class="line"><span class="string">\[</span> $helpflag -eq <span class="number">1</span> <span class="string">\]</span> &amp;&amp; Usage &amp;&amp; exit <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> <span class="string">\[</span> $addressflag -ne <span class="number">1</span> -o $notifyflag -ne <span class="number">1</span> <span class="string">\];</span> <span class="keyword">then</span></span><br><span class="line">  Usage</span><br><span class="line">  exit <span class="number">2</span></span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">mode=$&#123;mode:-mb&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">case</span> $notify <span class="keyword">in</span></span><br><span class="line"><span class="string">'master'</span>)</span><br><span class="line">  <span class="keyword">if</span> <span class="string">\[</span> $serviceflag -eq <span class="number">1</span> <span class="string">\];</span> <span class="keyword">then</span></span><br><span class="line">      RestartService $&#123;services<span class="string">\[*\]&#125;</span></span><br><span class="line">  fi</span><br><span class="line">  Notify master</span><br><span class="line">  ;;</span><br><span class="line"><span class="string">'backup'</span>)</span><br><span class="line">  <span class="keyword">if</span> <span class="string">\[</span> $serviceflag -eq <span class="number">1</span> <span class="string">\];</span> <span class="keyword">then</span></span><br><span class="line">    <span class="keyword">if</span> <span class="string">\[</span> <span class="string">"$mode"</span> == <span class="string">'mb'</span> <span class="string">\];</span> <span class="keyword">then</span></span><br><span class="line">      StopService $&#123;services<span class="string">\[*\]&#125;</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">      RestartService $&#123;services<span class="string">\[*\]&#125;</span></span><br><span class="line">    fi</span><br><span class="line">  fi</span><br><span class="line">  Notify backup</span><br><span class="line">  ;;</span><br><span class="line"><span class="string">'fault'</span>)</span><br><span class="line">  Notify fault</span><br><span class="line">  ;;</span><br><span class="line">*)</span><br><span class="line">  Usage</span><br><span class="line">  exit <span class="number">4</span></span><br><span class="line">  ;;</span><br><span class="line">esac</span><br><span class="line"></span><br><span class="line">(<span class="number">2</span>) 在keepalived.conf配置文件中，其调用方法如下所示：</span><br><span class="line"></span><br><span class="line">notify<span class="string">\_master</span> <span class="string">"/etc/keepalived/notify.sh -n master -a VIP\_address"</span></span><br><span class="line">notify<span class="string">\_backup</span> <span class="string">"/etc/keepalived/notify.sh -n backup -a VIP\_address"</span></span><br><span class="line">notify<span class="string">\_fault</span> <span class="string">"/etc/keepalived/notify.sh -n fault -a VIP\_address"</span></span><br><span class="line"></span><br><span class="line">(<span class="number">3</span>)修改master/slave 的keepalived配置文件：、  </span><br><span class="line"></span><br><span class="line">master:</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> vim /etc/keepalived/keepalived.conf</span><br><span class="line"></span><br><span class="line">! Configuration File <span class="keyword">for</span> keepalived</span><br><span class="line"></span><br><span class="line">global_defs &#123;</span><br><span class="line">notification_email &#123;</span><br><span class="line"><span class="number">2399447849</span>@qq.com</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">notification<span class="string">\_email\_from</span> root</span><br><span class="line">smtp_server <span class="number">127.0</span>.<span class="number">0.1</span></span><br><span class="line">smtp<span class="string">\_connect\_timeout</span> <span class="number">30</span></span><br><span class="line">router<span class="string">\_id</span> LVS<span class="string">\_DEVEL</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">vrrp<span class="string">\_script</span> chk<span class="string">\_schedown</span> &#123;</span><br><span class="line">script <span class="string">"\[ -e /etc/keepalived/down \] &amp;&amp; exit 1 || exit 0"</span></span><br><span class="line">interval <span class="number">1</span></span><br><span class="line">weight -<span class="number">5</span></span><br><span class="line">fall <span class="number">2</span></span><br><span class="line">rise <span class="number">1</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">vrrp<span class="string">\_instance</span> VI<span class="string">\_1</span> &#123;</span><br><span class="line">state MASTER</span><br><span class="line">interface eth0</span><br><span class="line">virtual<span class="string">\_router\_id</span> <span class="number">60</span></span><br><span class="line">priority <span class="number">101</span></span><br><span class="line">advert_int <span class="number">1</span></span><br><span class="line">authentication &#123;</span><br><span class="line">auth_type PASS</span><br><span class="line">auth_pass <span class="number">1111</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">virtual_ipaddress &#123;</span><br><span class="line"><span class="number">192.168</span>.<span class="number">254.200</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">track_script &#123;</span><br><span class="line">     chk_schedown</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">#-&gt;增加以下三行(注：在slave上面也一样添加这三行，此处略)</span></span><br><span class="line">    notify_master <span class="string">"/etc/keepalived/notify.sh -n master -a 192.168.254.200"</span></span><br><span class="line">    notify_backup <span class="string">"/etc/keepalived/notify.sh -n backup -a 192.168.254.200"</span></span><br><span class="line">    notify_fault <span class="string">"/etc/keepalived/notify.sh -n fault -a 192.168.254.200"</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">virtual_server <span class="number">192.168</span>.<span class="number">254.200</span> <span class="number">80</span> &#123;</span><br><span class="line">delay_loop <span class="number">6</span></span><br><span class="line">lb_algo rr</span><br><span class="line">lb_kind DR</span><br><span class="line">nat_mask <span class="number">255.255</span>.<span class="number">255.0</span></span><br><span class="line"><span class="comment">#persistence_timeout 50</span></span><br><span class="line">protocol TCP</span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">real_server <span class="number">192.168</span>.<span class="number">254.45</span> <span class="number">80</span>  &#123;</span><br><span class="line">weight <span class="number">1</span></span><br><span class="line">HTTP_GET &#123;</span><br><span class="line">    url &#123;</span><br><span class="line">      path /</span><br><span class="line">      status_code <span class="number">200</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">connect_timeout <span class="number">3</span></span><br><span class="line">nb<span class="string">\_get\_retry</span> <span class="number">3</span></span><br><span class="line">delay<span class="string">\_before\_retry</span> <span class="number">3</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">real_server <span class="number">192.168</span>.<span class="number">254.46</span> <span class="number">80</span> &#123;</span><br><span class="line">weight <span class="number">1</span></span><br><span class="line">HTTP_GET &#123;</span><br><span class="line">url &#123;</span><br><span class="line">path /</span><br><span class="line">status_code <span class="number">200</span></span><br><span class="line">&#125;</span><br><span class="line">connect_timeout <span class="number">3</span></span><br><span class="line">nb<span class="string">\_get\_retry</span> <span class="number">3</span></span><br><span class="line">delay<span class="string">\_before\_retry</span> <span class="number">3</span></span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">sorry_server <span class="number">127.0</span>.<span class="number">0.1</span> <span class="number">80</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">  (<span class="number">4</span>)添加脚本： 讲上述的脚本添加至master和slave的<span class="regexp">/etc/keepalived/</span>目录下(注意权限)：</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> ll /etc/keepalived</span><br><span class="line">总用量 <span class="number">8</span></span><br><span class="line">-rw-r--r--. <span class="number">1</span> root root <span class="number">1748</span> <span class="number">10</span>月 <span class="number">30</span> <span class="number">17</span>:<span class="number">08</span> keepalived.conf</span><br><span class="line">-rwxr-xr-x. <span class="number">1</span> root root <span class="number">2380</span> <span class="number">10</span>月 <span class="number">30</span> <span class="number">00</span>:<span class="number">57</span> notify.sh</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">#-&gt;复制至slave</span></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> scp <span class="regexp">/etc/keepalived/notify.sh 192.168.254.48:/etc/keepalived/</span></span><br><span class="line"></span><br><span class="line">(<span class="number">5</span>)测试一下脚本可用性：</span><br><span class="line"></span><br><span class="line"><span class="string">\[root@slave</span> keepalived<span class="string">\]#</span> ./notify.sh --help</span><br><span class="line">Usage: notify.sh <span class="string">\[-m|--mode</span> &#123;mm|mb&#125;<span class="string">\]</span> <span class="string">\[-s|--service</span> SERVICE1,...<span class="string">\]</span> &lt;-a|--address VIP&gt;  &lt;-n|--notify &#123;master|backup|falut&#125;&gt;</span><br><span class="line">Usage: notify.sh -h|--help</span><br><span class="line"><span class="string">\[root@slave</span> keepalived<span class="string">\]#</span> ./notify.sh -m mb -a <span class="number">2.2</span>.<span class="number">2.2</span> -n master</span><br><span class="line"><span class="string">\[root@slave</span> keepalived<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">查看邮件: [![<span class="number">12</span>](https:<span class="regexp">//raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/12.png)](https://</span>raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/<span class="number">2014</span>/<span class="number">10</span>/<span class="number">12.png</span>) 在模拟故障时重启一下keepalived,以免前面的实验造成影响。 注：现在已经可以成功收到邮件，通知脚本可用； (<span class="number">6</span>)故障模拟： &lt;<span class="number">1</span>&gt;先重启主备keepalived服务</span><br><span class="line"></span><br><span class="line">master:</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> service keepalived restart</span><br><span class="line">停止 keepalived：                                          <span class="string">\[确定\]</span></span><br><span class="line">正在启动 keepalived：                                      <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span></span><br><span class="line">slave:</span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> service keepalived restart</span><br><span class="line">停止 keepalived：                                          <span class="string">\[确定\]</span></span><br><span class="line">正在启动 keepalived：                                      <span class="string">\[确定\]</span></span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">&lt;<span class="number">2</span>&gt;正常情况下此时VIP在master上面</span><br><span class="line"></span><br><span class="line">master:</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span> ip a</span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line">inet <span class="number">192.168</span>.<span class="number">254.200</span>/<span class="number">32</span> scope <span class="built_in">global</span> eth0</span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line"><span class="string">\[root@master</span> ~<span class="string">\]#</span></span><br><span class="line"></span><br><span class="line">&lt;<span class="number">3</span>&gt;在master的/etc/keepalived目录下 touch一个文件”down”</span><br><span class="line"></span><br><span class="line">master:</span><br><span class="line"><span class="string">\[root@master</span> keepalived<span class="string">\]#</span> touch down</span><br><span class="line"></span><br><span class="line">&lt;<span class="number">4</span>&gt;观察VIP 转移情况</span><br><span class="line"></span><br><span class="line">slave:</span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span> ip a</span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line">inet <span class="number">192.168</span>.<span class="number">254.200</span>/<span class="number">32</span> scope <span class="built_in">global</span> eth0</span><br><span class="line">.......</span><br><span class="line">.......</span><br><span class="line"><span class="string">\[root@slave</span> ~<span class="string">\]#</span></span><br></pre></td></tr></table></figure></p>
<p><5>结果查看—&gt;邮件收取 <a href="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/13.png" target="_blank" rel="noopener"><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/13.png" alt="13"></a> <6>Client访问测试 <a href="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/14.png" target="_blank" rel="noopener"><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2014/10/14.png" alt="14"></a> 从上可以看到，在keepalived主备切换时，不仅能够发送邮件，而且访问服务也没有问题； 至此Lvs+Keepalived的基本应用实验演示完毕！</6></5></p>

      
    </div>
    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>


  
</div>
    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="../../../../tags/Floating/" rel="tag"># Floating</a>
          
            <a href="../../../../tags/keepalived/" rel="tag"># keepalived</a>
          
            <a href="../../../../tags/lvs/" rel="tag"># lvs</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="../../../08/28/tomcat-e7-8e-af-e5-a2-83-e6-90-ad-e5-bb-ba-e5-8f-8ajsp-e7-ab-99-e7-82-b9-e5-ae-9e-e7-8e-b0/" rel="next" title="Tomcat环境搭建及jsp站点实现">
                <i class="fa fa-chevron-left"></i> Tomcat环境搭建及jsp站点实现
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="../../../11/04/zabbix-e6-b8-85-e7-90-86-e8-bf-87-e4-b9-85-e7-9a-84-e5-8e-86-e5-8f-b2-e4-bf-a1-e6-81-af/" rel="prev" title="Zabbix 清理过久的历史信息">
                Zabbix 清理过久的历史信息 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png" alt="OutMan">
            
              <p class="site-author-name" itemprop="name">OutMan</p>
              <p class="site-description motion-element" itemprop="description">😊</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="../../../../archives/">
              
                  <span class="site-state-item-count">79</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="../../../../categories/index.html">
                  <span class="site-state-item-count">22</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="../../../../tags/index.html">
                  <span class="site-state-item-count">46</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/guomaoqiu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i></a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:guomaoqiu@google.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i></a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OutMan</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="../../../../lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="../../../../js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="../../../../js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="../../../../js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="../../../../js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="../../../../js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
